package day17;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class TestCallable implements Callable<Integer> {
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 0; i < 100; i+=2) {
            sum += i;
            Thread.sleep(500);
            System.out.println("目前:"+sum);
        }
        return sum;
    }
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        TestCallable call = new TestCallable();
        //Callable接口要实现线程  必须借助于FutureTask类
        //套三层，底层是Runnable
        FutureTask<Integer> ft = new FutureTask(call);
        Thread t = new Thread(ft);
        t.start();
        //用来获取call()返回值的:属于线程阻塞状态
        //需要等待
        Integer sum = ft.get();
        System.out.println("结果："+sum);
    }
}

class ArrayList<S>{
    public void add(S t){

    }
}
